<?php
include '../controller/Conexao.php';
include '../model/Texto.php';

class TextoDAO{
	
	public function Insere(Texto $texto){
		try{
			mysql_query( "INSERT INTO texto( nome
											,item
											,texto)
									  VALUES ('".$texto->getNome()."'
									  		 ,'".$texto->getItem()."'
									  		 ,'".$texto->getTexto()."')" ) or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
	public function Remove($id){
		try{
			mysql_query("delete from texto where idtexto=$id") or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
	public function Altera(Texto $texto){
		try{
			mysql_query("UPDATE texto SET nome 	= 	'".$texto->getNome()."'
										, item 	= 	'".$texto->getItem()."'
										, texto	= 	'".$texto->getTexto()."'
									   WHERE idtexto = ".$texto->getIdTexto() ) or die (mysql_error());
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
							
		//header("location:../view/ListaDevices.php");
	}
	public static function GetTextos() {
		try {
			$rs = mysql_query ( 'select * from texto' ) or die ( mysqli_error () );
			$arrayTexto= array();
			while ( $row = mysql_fetch_array( $rs ) ) {
				array_push( $arrayTexto, $row["texto"] );
			}
			return $arrayTexto;
		} catch ( Exception $ex ) {
			echo "Erro: " . $ex->getMessage ();
		}
	}
	public function Lista(){
		try{			
			$rs = mysql_query( 'select * from texto') or die(mysqli_error()) ;
			$result = array();
			while($row = mysql_fetch_object($rs)){
				array_push($result, $row);
			}	
			return $result;
		}catch ( Exception $ex ){
			echo "Erro: ".$ex->getMessage();
		}
	}
	
}	
	
?>
